//
//  ShowProgressController.m
//  HappyTravel
//
//  Created by JiePan’s Mac on 2018/8/6.
//  Copyright © 2018年 Apple. All rights reserved.
//

#import "ShowProgressController.h"
#import "HTModel.h"

@interface ShowProgressController () <UITextViewDelegate> {
    
    float noteTextHeight;
    float pickerViewHeight;
}
@property(nonatomic, assign)double  note;
@property(nonatomic, copy)NSArray *  arrayStatics;
@property(nonatomic, assign)int  changedImageImg;
@property(nonatomic, assign)NSInteger  travleLabelFlow;



@property (nonatomic, strong) NSMutableArray *ablumArray;

@end

@implementation ShowProgressController

-(CGFloat)checkHasEnd:(NSString *)lineShow {
     int out = 8090;
     CGFloat noneApril = 3004.0;
    CGFloat inflammableConsistent = 0;
    out = 5294;
    inflammableConsistent /= MAX(out, 1);
    noneApril = 5022;
    inflammableConsistent -= noneApril;

    return inflammableConsistent;

}





- (void)viewWillAppear:(BOOL)animated {

         CGFloat ostracizeAlthough = [self checkHasEnd:@"ichthyologist"];

      if (ostracizeAlthough >= 42) {
             NSLog(@"%f",ostracizeAlthough);
      }



    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.barTintColor = ThemeColor;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:COLOR_RGB(255, 255, 255)}];
    [[UIApplication sharedApplication] setStatusBarStyle:(UIStatusBarStyleLightContent)];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}

-(UITableView *)viewsInit:(CGFloat)back btn:(Boolean)btn {
     UIButton * backgroud = [[UIButton alloc] initWithFrame:CGRectZero];
    UITableView * brown = [[UITableView alloc] init];
    brown.alpha = 0.9;
    brown.backgroundColor = [UIColor colorWithRed:26 / 255.0 green:62 / 255.0 blue:139 / 255.0 alpha:0.1];
    brown.frame = CGRectMake(221, 177, 0, 0);
    brown.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha: 0];
    brown.delegate = nil;
    brown.dataSource = nil;
    backgroud.frame = CGRectMake(272, 203, 0, 0);
    backgroud.alpha = 0.5;
    backgroud.backgroundColor = [UIColor colorWithRed:162 / 255.0 green:88 / 255.0 blue:253 / 255.0 alpha:0.6];

    return brown;

}





- (void)viewDidAppear:(BOOL)animated {

         UITableView * presence = [self viewsInit:9688.0 btn:YES];

      [self.view addSubview: presence];



    [super viewDidAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

-(UIImageView *)disappearMemoryArr{
     UILabel * arr = [[UILabel alloc] initWithFrame:CGRectMake(76, 378, 0, 0)];
    UIImageView * idea = [[UIImageView alloc] initWithFrame:CGRectZero];
    idea.alpha = 0.7;
    idea.backgroundColor = [UIColor colorWithRed:49 / 255.0 green:153 / 255.0 blue:181 / 255.0 alpha:0.9];
    idea.frame = CGRectMake(108, 151, 0, 0);
    idea.animationRepeatCount = 7;
    idea.image = [UIImage imageNamed:@"register_emotion"];
    idea.contentMode = UIViewContentModeScaleAspectFit;
    arr.backgroundColor = [UIColor colorWithRed:174 / 255.0 green:149 / 255.0 blue:93 / 255.0 alpha:1.0];
    arr.alpha = 1.0;
    arr.frame = CGRectMake(212, 24, 0, 0);
    arr.textAlignment = NSTextAlignmentLeft;
    arr.font = [UIFont systemFontOfSize:11];
    arr.text = @"";
    arr.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha: 0];

    return idea;

}





- (void)viewWillDisappear:(BOOL)animated {

         UIImageView * measurementHybrid = [self disappearMemoryArr];

      [self.view addSubview: measurementHybrid];



    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:(UIStatusBarStyleDefault)];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"Add";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self didUpdateBecome];
}

#pragma mark - CustomMethod
- (void)didUpdateBecome{
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 30, 30);
    [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [leftBtn addTarget:self action:@selector(dateTextField) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 60, 30);
    [rightBtn setTitle:@"Publish" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [rightBtn addTarget:self action:@selector(deleteBtn) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
    self.showInView = self.view;
    [self initPickerView];
    [self initViews];
}

- (void)initViews {
    
    _noteTextBackgroudView = [[UIView alloc]init];
    _noteTextBackgroudView.backgroundColor = [UIColor colorWithWhite:1 alpha:1];
    
    //TextView
    _noteTextView = [[UITextView alloc]init];
    _noteTextView.keyboardType = UIKeyboardTypeDefault;
    [_noteTextView setFont:[UIFont fontWithName:@"Heiti SC" size:16]];
    [_noteTextView setTextColor:[UIColor blackColor]];
    _noteTextView.delegate = self;
    
    //PlaceHolderLabel
    _placeholderLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 8, ScreenWidth-20, 30)];
    _placeholderLabel.text = @"Please enter your travel mood log...";
    _placeholderLabel.textColor = UIColorOfHex(0xCDCDCD);
    _placeholderLabel.enabled = NO;
    _placeholderLabel.font = [UIFont systemFontOfSize:14];
    _placeholderLabel.backgroundColor = [UIColor clearColor];
    [self.noteTextView addSubview:self.placeholderLabel];
    
    [self.view addSubview:self.noteTextBackgroudView];
    [self.view addSubview:self.noteTextView];
    
    [self monthArr];
}

-(NSDictionary *)foregroundStartHas:(NSString *)configShow tableIndex:(NSInteger)tableIndex ain:(double)ain {
    NSMutableDictionary * shearArresting = [NSMutableDictionary dictionaryWithCapacity:239];

    return shearArresting;

}





- (void)monthArr{

         NSDictionary * acute = [self foregroundStartHas:@"financing" tableIndex:3374 ain:2978.0];

      [acute enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
          if ([key isEqualToString:@"september"]) {
              NSLog(@"value: %@", obj);
          }else {
              NSLog(@"key: %@, value: %@", key, obj);
          }
      }];



    
    if (!noteTextHeight) {
        noteTextHeight = 100;
    }
    
    _noteTextBackgroudView.frame = CGRectMake(0, SafeAreaTopHeight, ScreenWidth, noteTextHeight);
    
    _noteTextView.frame = CGRectMake(15, SafeAreaTopHeight, ScreenWidth-30, noteTextHeight);
    
    //PhotoPicker
    [self updatePickerViewFrameY:_noteTextView.frame.origin.y + _noteTextView.frame.size.height];
}

- (void)dateLabel{
    
    CGRect orgRect = self.noteTextView.frame;
    
    CGSize size = [self.noteTextView sizeThatFits:CGSizeMake(self.noteTextView.frame.size.width, MAXFLOAT)];
    
    orgRect.size.height = size.height+10;
    
    if (orgRect.size.height > 100) {
        noteTextHeight = orgRect.size.height;
    }else {
        noteTextHeight = 100;
    }
    
    [self monthArr];
}

#pragma mark - UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    
    [self dateLabel];
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView {
    
    _noteTextView.text = textView.text;
    if (textView.text.length == 0) {
        _placeholderLabel.text = @"Please enter your travel mood log...";
    }else {
        _placeholderLabel.text = @"";
    }
}

#pragma maek - checkInput
- (BOOL)placeLabel{
    
    if (self.noteTextView.text.length == 0) {
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Hint" message:@"Please enter your travel mood log" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleCancel handler:nil];
        [alertController addAction:actionCacel];
        [self presentViewController:alertController animated:YES completion:nil];
        
        return NO;
    }else if (self.imageArray.count == 0) {
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Hint" message:@"Please add photos" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleCancel handler:nil];
        [alertController addAction:actionCacel];
        [self presentViewController:alertController animated:YES completion:nil];
        
        return NO;
    }
    
    return YES;
}

#pragma mark - touches events
- (void)dateTextField{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)deleteBtn{
    
    if ([self placeLabel]) {
        
        NSArray *imageArr = self.arrSelected;
        
        NSMutableArray *imageDataArray = [NSMutableArray array];
        for (ALAsset *asset in imageArr) {
            UIImage *image = [[UIImage alloc] initWithCGImage:[[asset defaultRepresentation] fullScreenImage]];
            NSData *imgData = UIImageJPEGRepresentation(image, 1.0);
            [imageDataArray addObject:imgData];
        }
        
        NSArray *tempArr = [HTSingleton readModelArrayForDocument:AblumModelPath];
        if (tempArr != nil) {
            [self.ablumArray addObjectsFromArray:tempArr];
        }

        HTModel *photos = [HTModel new];
        photos.imagePhotos = imageDataArray;
        photos.content = self.noteTextView.text;
        photos.currentTime = [HTSingleton getCurrentDay];
        [self.ablumArray addObject:photos];

        [HTSingleton saveModelDictionaryInDocument:self.ablumArray andPath:AblumModelPath];
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}

-(CGFloat)beginFor:(float)imaHeader place:(long)place {
     double modelIngleton = 5784.0;
     float left = 3898.0;
     CGFloat titles = 3786.0;
    CGFloat torpedoStanch = 0;
    modelIngleton += 79;
    torpedoStanch -= modelIngleton;
    left += 8;
    torpedoStanch -= left;
    titles = left - titles;
    torpedoStanch -= titles;

    return torpedoStanch;

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

         CGFloat aerateGroom = [self beginFor:945.0 place:2784];

      if (aerateGroom <= 94) {
             NSLog(@"%f",aerateGroom);
      }



    [self.view endEditing:YES];
}

#pragma mark - getter
- (NSMutableArray *)ablumArray {
    if (!_ablumArray) {
        _ablumArray = [[NSMutableArray alloc] init];
    }
    return _ablumArray;
}
@end
